﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

/// <summary>
/// 我的自定义Button，继承 Button
/// </summary>
public class MyButton : Button
{
    public ushort section;  //1 拼装台 2 背包
    public int posX;
    public int posY;
    //public int bagIndex;
    public delegate void MouseHandler(CombineUIEvent evt, int id);  

    public event MouseHandler OnDragTrigged;
    public event MouseHandler OnShowTrigged;

    public override void OnPointerDown(PointerEventData eventData)
    {  
        base.OnPointerDown(eventData);
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            int id = 0;
            switch (section)
            {
                case 1:
                    {
                        if (WorkshopLogic.Grid.GridList[posX][posY].isOccupied == true)
                        {
                            id = WorkshopLogic.Grid.GridList[posX][posY].occupyID;
                        }
                        break;
                    }
                case 2:
                    {
                        var button = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
                        int num = button.name[4] - 49;
                        id = TopFuncLogic.GetId(num);
                        break;
                    }
            }
            OnDragTrigged(CombineUIEvent.DragObject, id);
            OnShowTrigged(CombineUIEvent.ShowObjectValues, id);
        }
       /* else if(eventData.button == PointerEventData.InputButton.Right)
        {
            if(section == 1)
            {
                OnShowTrigged(CombineUIEvent.BenchToBag, id);
            }
        }*/
    }

    public override void OnPointerUp(PointerEventData eventData)
    {
        base.OnPointerUp(eventData);
        OnDragTrigged(CombineUIEvent.DragObject, -1);
    }
}